<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.page{
	height:30px;
	margin: 10px 0 0 10px;
}
.page a{
    text-decoration: none;
}
.page-left{
	text-align:left;
}
.page-right{
    float: right;
}
.page-first-enable{
	width:40px; 
	height:15px; 
	background: url('images/main_54.gif');
	border: 0px;
	cursor: pointer;
	margin-right: 5px;
}
.page-first-disable{
	width:40px; 
	height:15px; 
	background: url('images/main_54.gif');
	border: 0px;
	cursor: text;
	margin-right: 5px;
}
.page-pre-enable{
	width:40px; 
	height:15px; 
	background: url('images/main_56.gif');
	border: 0px;
	cursor: pointer;
	margin-right: 5px;
}
.page-pre-disable{
	width:40px; 
	height:15px; 
	background: url('images/main_56.gif');
	border: 0px;
	cursor: text;
	margin-right: 5px;
}
.page-next-enable{
	width:40px; 
	height:15px; 
	background: url('images/main_58.gif');
	border: 0px;
	cursor: pointer;
	margin-right: 5px;
}
.page-next-disable{
	width:40px; 
	height:15px; 
	background: url('images/main_58.gif');
	border: 0px;
	cursor: text;
	margin-right: 5px;
}
.page-last-enable{
	width:40px; 
	height:15px; 
	background: url('images/main_60.gif');
	border: 0px;
	cursor: pointer;
	margin-right: 5px;
}
.page-last-disable{
	width:40px; 
	height:15px; 
	background: url('images/main_60.gif');
	border: 0px;
	cursor: text;
	margin-right: 5px;
}
.page-go{
   margin-top: 10px;
}
.page-num{
   width:50px;
   margin-top: 10px;
}
.page-pages{
  margin-top: 10px;
}
.page-goto{
    width:40px;
    height:15px; 
    background: url('');border: 0px;
    margin-top: 10px;
}
</style>
<script type="text/javascript">
function pageGoUrl(url, totalPages) {
	if (totalPages<=0) {return;}
    var page = document.getElementById("pageGotoNum").value;
   if (page=="" || page <=0) {return;} 
   if (page > totalPages) {return;}
  
   document.location.href = url+"page="+page;
}
</script>
</head>

<body>
	<div class="page">
    	<%	
    		// 当前页
    		int p = 1;
    	    String currentPage = request.getParameter("page");
    		if (null != currentPage || !"".equals(currentPage)) {
    			p = Integer.valueOf(currentPage);
    		}
    		// 总条数
    		int total = 0;
    		String totalPage = request.getParameter("total");
    		if (null != totalPage && !"".equals(totalPage)) {
    			total = Integer.valueOf(totalPage);
    		}
    		
    		// 访问地址
    		String loc = request.getParameter("loc");
    		if (null != loc && !"".equals(loc)) {
    			if (loc.indexOf("??") > -1) {
    				loc = loc.replaceAll("\\?\\?","&");
    			}
    			if (loc.indexOf("?") < 0) {
    				loc += "?";
    			}
    			else {
    				loc += "&";
    			}
    		}
    		
	    	/* 总页数 */
			int tp = 1;
			int cp = Integer.valueOf(p);
			int pages = 25;
			String ps = request.getParameter("pageSize");
			if (null != ps && !ps.equals("")) {
				pages = Integer.valueOf(ps);
			}
		
   			tp = total/pages;
   			if (total%pages != 0) {
   				tp = tp + 1;
   			}
   			if (tp < 1) {
   				tp = 1;
   			}
   			
   			out.print("<span class='page-left'>共有"+total+"条记录，当前第"+p+"页，共"+tp+"页</span>");
   			out.print("<span class='page-right'>");
           
   			if (tp > 1) {
   				if (p==1) {
   					out.print("<a class='page-first-disable'>&nbsp&nbsp&nbsp&nbsp&nbsp</a>");
   					out.print("<a class='page-pre-disable'>&nbsp&nbsp&nbsp&nbsp&nbsp</a>");
   				} else {
   					out.print("<a class='page-first-enable' href='"+ loc + "page=1'>&nbsp&nbsp&nbsp&nbsp&nbsp</a>");
   					out.print("<a class='page-pre-enable' href='"+loc+"page="+(p-1)+"'>&nbsp&nbsp&nbsp&nbsp&nbsp</a>");
   				}
   				if (p==tp) {
   					out.print("<a class='page-next-disable'>&nbsp&nbsp&nbsp&nbsp&nbsp</a>");
   					out.print("<a class='page-last-disable'>&nbsp&nbsp&nbsp&nbsp&nbsp</a>");
   				} else {
   					out.print("<a class='page-next-enable' href='"+loc + "page=" +(p+1)+"')>&nbsp&nbsp&nbsp&nbsp&nbsp</a>");
   					out.print("<a class='page-last-enable' href='"+loc+"page="+tp+"')>&nbsp&nbsp&nbsp&nbsp&nbsp</a>");
   				}
   				out.print("<span class='page-go'>转到</span>");
   				out.print("<input type='text' class='page-num' id='pageGotoNum'/>");
   				out.print("<span class='page-pages'>页</span>");
   				out.print("<a class='page-goto' href='javascript:;' onclick='pageGoUrl(\""+loc+"\", "+tp+")'>转</a>");
   			}
   			out.print("</span>");
   		%>
    </div>
</body>
</html>
